import {fileClassOpenListener,createFileStudentList} from './historyClassListener.js'
// main page listener
let unfoldOpenListener = () => {
    $(".unfold-open-click").each(function () {
        $(this).on("click", (e) => {
            let {index} = e.target.dataset
            $(`.unfold-bubble${index}`).slideToggle();
        });
    });
};

// main page listener
let comingListener = () => {
    $(".coming").each(function (index) {
        $(this).on("click", (e) => {
            let {index } = e.target.dataset
            index = parseInt(index)
            if (e.target.style.transform === "rotate(360deg)") {
                e.target.style.transform = "rotate(180deg)";
                window.requestAnimationFrame(() => {
                    $(`.component-class-bottom-list-next${index}`).slideUp("slow");
                });
            } else {
                e.target.style.transform = "rotate(360deg)";
                $(`.component-class-bottom-list-next${index}`).slideDown("slow");
            }
        });
    });
};

// main page listener
let passByListener = () => {
    $(".pass-by").each(function (index) {
        $(this).on("click", (e) => {
            let {index } = e.target.dataset
            index = parseInt(index)
            if (e.target.style.transform === "rotate(360deg)") {
                e.target.style.transform = "rotate(180deg)";
                window.requestAnimationFrame(() => {
                    $(`.component-class-bottom-list-before${index}`).slideUp();
                });
            } else {
                e.target.style.transform = "rotate(360deg)";
                $(`.component-class-bottom-list-before${index}`).slideDown();
            }
        });
    });
};

// main page slide
let studentUp = () => {
    $(".student-xiangxia").each(function (index) {
        $(this).on("click", (e) => {
            let {index } = e.target.dataset
            index = parseInt(index)
            if (e.target.style.transform === "rotate(360deg)") {
                e.target.style.transform = "rotate(180deg)";
            } else {
                e.target.style.transform = "rotate(360deg)";
            }
            $(`.component-class-bottom-student-detail${index}`).slideToggle();
        });
    });
};

// main page listener
let fileClassListener = (currentOpenClassName) => {
    $(".file-class")[0].addEventListener("click", () => {
        $(".component-wrap")[0] && $(".component-wrap")[0].remove();
        fileClassOpenListener();
        createFileStudentList();
        currentOpenClassName = "component-wrap-file";
    });
};

export {
    unfoldOpenListener,
    comingListener,
    passByListener,
    studentUp,
    fileClassListener
}